<template>
  <div>
    <div class="from">
      <van-form @submit="onSubmit">
         <van-field
          v-model="form.phone"
          name="phone"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          v-model="form.nickname"
          name="nickname"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="form.password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        
        
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >提交</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { Notify } from 'vant';
export default {
  props: {},
  data() {
    return {
      form:{
         password: '',
         phone:'',
         nickname:''
      } 
    };
  },
  computed: {},
  created() {},
  mounted() {},
  watch: {},
  methods: {
   onSubmit(values) { // 注册提交
      let verify = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/
      if(verify.test(values.phone)){
         this.$api.register(this.form).then(res=>{
            this.$router.go(-1)
            Notify({ type: 'success', message: '注册成功,请登录' });
         })
      }else{
         Notify({ type: 'warning', message: '请您输入正确手机号' });
         return
      }
    },
  },
  components: {},
};
</script>

<style scoped lang="less">
.from{
   margin: 50% auto;
}
</style>
